package components {
import com.greensock.TweenNano;

import core.Facade;

import events.PromptWIndowEvent;

import flash.display.Bitmap;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;

public class PromptWindow extends Sprite {
    private var _back:Bitmap;
    private var _titleField:TextField;
    private var _messageField:TextField;

    private var btn_ok:OldButton;
    private var btn_cancel:OldButton;



    public function PromptWindow(back:Bitmap) {
        addChild(back);
        _titleField = new TextField();
        _titleField.x = 80;
        _titleField.y = 60;
        addChild(_titleField);
        _messageField = new TextField();
        _messageField.x = 45;
        _messageField.y = 120;
        addChild(_messageField);

        btn_ok = new OldButton("Заново");
        btn_cancel = new OldButton("Выйти");
        btn_cancel.x = 71;
        btn_cancel.y = 335;
        btn_ok.x = 198;
        btn_ok.y = 335;

        addChild(btn_cancel);
        addChild(btn_ok);

        btn_cancel.addEventListener(MouseEvent.CLICK,cancel_click);
        btn_ok.addEventListener(MouseEvent.CLICK, ok_click);


    }

    private function cancel_click(event:MouseEvent):void {
        dispatchEvent(new PromptWIndowEvent(PromptWIndowEvent.PROMPT_DECEPTED));
        TweenNano.to(this,0.5,{alpha:0, y:y+10, onComplete:hide});
    }
    private function ok_click(event:MouseEvent):void {
        dispatchEvent(new PromptWIndowEvent(PromptWIndowEvent.PROMPT_ACCEPTED));
        TweenNano.to(this,0.5,{alpha:0, y:y+10, onComplete:hide});
    }

    public function destroy(event:Event):void
    {
        parent.removeChild(this);
    }


    public function show():void
    {
        var facade:Facade = Facade.getInstance();
        facade.stage.addChild(this);
        this.x =(facade.stage.width-366)*0.5;
        this.y = (facade.stage.height-374)*0.5;
    }
    public function hide():void
    {
        Facade.getInstance().stage.removeChild(this);
    }
    public function set title(p_title:String):void
    {
        _titleField.text = p_title;
    }
    public function set message(p_message:String):void
    {
        _messageField.text = p_message;
    }


}



}

